import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:flutter_food/core/model/category_model.dart';

class LocalRepository {
  static Future<List<CategoryModel>> getCategoryData() async {
    // 加载json文件
    final jsonStr = await rootBundle.loadString("assets/json/category.json");
    // 将jsonStr转为map或者list
    final jsonMap = json.decode(jsonStr);
    // 去除所有category
    final categoryListJson = jsonMap['category'];
    // 将map转换为model
    List<CategoryModel> categoryList = [];
    for (var category in categoryListJson) {
      categoryList.add(CategoryModel.fromJson(category));
    }
    return categoryList;
  }
}
